home *** CD-ROM | disk | FTP | other *** search
-
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
- /* */
- /* Prototype HP15C Calculator */
- /* James C. Ullrey */
- /* INRESCO */
- /* © 1990 */
- /* Version 13.97a */
- /* */
- /* CONTROL SEGMENT */
- /* */
- /* */
- /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
-
-
- /*****************************************************************/
- /* I N C L U D E S
- /*****************************************************************/
-
- #ifndef __C14__
- #include "PredatorPrey.h"
- #endif
- #include "calc_controls.h"
- #include <Controls.h>
- #include "calc_update.h"
-
-
-
- /********************************************************************
- /* G L O B A L V A R I A B L E D E C L A R A T I O N S
- /********************************************************************/
-
-
-
-
-
- /*****************************************************************/
- /* P R O T O T Y P E S
- /*****************************************************************/
-
-
-
-
- pascal void do_cntl_button (ControlHandle cntl_hndl, short part_code);
- short compute_scroll (ControlHandle cntl_hndl,
- long percent,
- short old_value,
- short direction);
-
-
-
- /*****************************************************************/
- /*****************************************************************/
- /*
- /* R O U T I N E S
- /*
- /*****************************************************************/
- /*****************************************************************/
-
-
- void controls_seg(){} /* for reference in "UnloadSeg()" calls */
-
-
-
-
-
-
- /*****************************************************************/
- /* D O C O N T R O L S - process mousedown in controls
- /*****************************************************************/
-
- /**
- This routine handles mouse down events in the scrollbars. For the button
- elements of the scrollbars (up/down arrow & up/down page) the resultant
- activity is handled by the call-back procedure "do_cntl_butn" which in turn
- calls the routine "do_scroll()". For the thumb the activity is handled
- directly by the routine "do_scroll()". It is assumed that if the thumb was
- not the thumb of the horizontal scrollbar thenm it was the thumb of the
- vertical scrollbar.
- **/
-
-
- void do_controls(Point local_point,WindowPtr wPtr,ControlHandle cntl_hndl,short control_part)
- //Point local_point;
- //WindowPtr wPtr;
- //ControlHandle cntl_hndl;
- //short control_part;
-
- {
- ControlActionUPP myControlProc;
-
- myControlProc = NewControlActionProc((ProcPtr)do_cntl_button);
-
- switch(control_part)
- {
- case inUpButton: /* inUpButton = 20 */
- case inDownButton: /* inDownButton = 21 */
- case inPageUp: /* inPageUp = 22 */
- case inPageDown: /* inPageDown = 23 */
- //TrackControl(cntl_hndl, local_point, (UniversalProcPtr)do_cntl_button);
- TrackControl(cntl_hndl, local_point, myControlProc);
- break;
-
- case inThumb: /* inThumb = 129 */
- if (
- #ifdef powerc
- TrackControl(cntl_hndl, local_point, (UniversalProcPtr)NIL)
- #else
- TrackControl(cntl_hndl, local_point, NIL)
- #endif /* powerc */
- )
- {
- do_scroll(wPtr,cntl_hndl);
- }
- break;
- }
-
- return;
-
- } /* end of do_controls() */
-
-
-
-
-
- /*****************************************************************/
- /* D O C N T L B U T T O N - Handle mousedowns in scrollbar buttons
- /*****************************************************************/
-
- /**
- Note that this is a callback procedure referenced in the "TrackControl()"
- calls in "do_controls()", above. It must be declared as a Pascal routine in
- order to have the calling sequence implemented properly for TrackControl().
- **/
-
-
- pascal void do_cntl_button(ControlHandle cntl_hndl,short part_code)
- //ControlHandle cntl_hndl;
- //short part_code;
-
- {
- short old_value, new_value;
- WindowPtr wPtr;
-
-
-
- /************* Check the control **********/
-
-
- if(part_code == NIL) return;
-
-
-
- /************* Adjust new control value as appropriate **********/
-
-
- old_value = GetCtlValue(cntl_hndl);
-
- switch(part_code)
- {
- case inUpButton:
- new_value = compute_scroll(cntl_hndl,15, old_value, SCROLL_UP);
- break;
-
- case inDownButton:
- new_value = compute_scroll(cntl_hndl, 15, old_value, SCROLL_DOWN);
- break;
-
- case inPageUp:
- new_value = compute_scroll(cntl_hndl, 90, old_value, SCROLL_UP);
- break;
-
- case inPageDown:
- new_value = compute_scroll(cntl_hndl, 90, old_value, SCROLL_DOWN);
- break;
- }
-
-
-
- /************* Go do the scrolling... **********/
-
-
- SetCtlValue(cntl_hndl, new_value);
-
- wPtr = (**cntl_hndl).contrlOwner;
-
- do_scroll(wPtr,cntl_hndl); /* this */
-
- return;
-
- } /* end of do_cntl_button() */
-
-
-
-
-
- /*****************************************************************/
- /* C O M P U T E S C R O L L - based on control values, window, etc
- /*****************************************************************/
-
- /**
- This routine computes the new value of the scrollbar controls (and thus the
- amount to scroll the window) based on min/max values of the controls and
- the percentage of the window that was specified to scroll. We are using
- a control-range that is numerically equal to the document size in pixels, so
- we can use "control-value-deltas" and "scroll-amounts" interchangeably.
- **/
-
-
- short compute_scroll(ControlHandle cntl_hndl,long the_percent,short old_value,short the_direction)
- //ControlHandle cntl_hndl;
- //long the_percent;
- //short old_value, the_direction;
-
- {
- short the_max, the_min, new_value;
- short h_size, v_size;
- WindowPtr wPtr;
- WObjsHandle w_objs_hndl;
- WPObjsHandle wp_objs_hndl;
- long amount_to_scroll;
-
-
-
- /************* get the info we need... **********/
-
-
- the_max = GetCtlMax(cntl_hndl);
- the_min = GetCtlMin(cntl_hndl);
-
- wPtr = (**cntl_hndl).contrlOwner;
- if(wPtr == gProgWindow)
- {
- wp_objs_hndl = (WPObjs**)GetWRefCon(wPtr);
- v_size = wPtr->portRect.bottom;
- }
- else
- {
- w_objs_hndl = (WObjs**)GetWRefCon(wPtr);
- v_size = wPtr->portRect.bottom - 15;
- }
-
- h_size = wPtr->portRect.right - 15; /* we're going to scroll a percentage of */
- /* the size of the drawing area of the */
- /* window. (window - scrollbar areas) */
-
-
-
- /************* Use height or width of window as appropriate **********/
-
- if(wPtr == gProgWindow)
- {
- amount_to_scroll = ((long)v_size * the_percent) / 100; /* vertical scroll */
- }
- else
- {
- if (cntl_hndl == (**w_objs_hndl).myHCntrlHdl)
- amount_to_scroll = ((long)h_size * the_percent) / 100; /* horizontal scroll */
- else
- amount_to_scroll = ((long)v_size * the_percent) / 100; /* vertical scroll */
- }
-
-
- /************* Don't go beyond max or min range of scrolling **********/
-
-
- new_value = (long)old_value + ( (long)the_direction * amount_to_scroll );
-
- if (new_value > the_max) new_value = the_max;
- if (new_value < the_min) new_value = the_min;
-
- return(new_value);
-
- } /* end of compute_scroll() */
-
-
-
-
-
- /*****************************************************************/
- /* D O S C R O L L - actually does the scrolling
- /*****************************************************************/
-
- /**
- This routine scrolls the drawing area of the window by the specified amount
- and updates the control values and saved scroll-amount point
- (current total scroll offset) in the window objects record. Note that the
- area scrolled by "ScrollRect()" is the intersection of the specified rectangle
- and the clip area, visRgn, portRect and portBits.bounds of the window. Thus
- although we specify a rectangle including the entire drawing area of the window,
- the palette does not get scrolled because it's outside the clip area we defined
- for the window.
- **/
-
-
- void do_scroll(WindowPtr wPtr,ControlHandle cntl_hndl)
- {
- short h_scroll, v_scroll;
- short howMuch;
- Rect bounds_rect;
- WObjs** w_objs_hndl;
- WPObjs** wp_objs_hndl;
- Point offset;
- ControlHandle h_cntl_hndl, v_cntl_hndl;
- RgnHandle my_rgn, saved_clip;
- long start_ticks, min_delay;
-
-
-
- /********* get current scroll offset amounts (WObjs "scrollAmount") **********/
-
- if(wPtr == gProgWindow)
- {
- wp_objs_hndl = (WPObjs**)GetWRefCon (wPtr);
- offset = (**wp_objs_hndl).scrollAmount;
- /*v_cntl_hndl = (**wp_objs_hndl).myVCntrlHdl;*/
- h_scroll = 0;
- /*howMuch = GetCtlValue(v_cntl_hndl);*/
- howMuch = GetCtlValue(cntl_hndl);
- v_scroll = offset.v - howMuch;
- LScroll( 0, v_scroll, progList );
- /*LDoDraw(TRUE,progList);*/
- }
- else
- {
- w_objs_hndl = (WObjs**)GetWRefCon (wPtr);
- offset = (**w_objs_hndl).scrollAmount;
- h_cntl_hndl = (**w_objs_hndl).myHCntrlHdl;
- v_cntl_hndl = (**w_objs_hndl).myVCntrlHdl;
- h_scroll = offset.h - GetCtlValue(h_cntl_hndl);
- v_scroll = offset.v - GetCtlValue(v_cntl_hndl);
- }
-
-
- if((h_scroll == 0) && (v_scroll == 0)) return;
-
- start_ticks = TickCount();
- min_delay = 12;
-
-
-
- /************* Set up the area to be scrolled (window - scrollbars) **********/
-
-
- SetRect(&bounds_rect,wPtr->portRect.left,
- wPtr->portRect.top,
- wPtr->portRect.right - 15,
- wPtr->portRect.bottom - 15);
-
-
-
- /************* Save the current state of the machine **********/
-
-
- SetPort(wPtr);
-
- saved_clip = NewRgn();
- GetClip(saved_clip);
-
-
-
- /********* Set clip area to exclude palette and go do the scrolling **********/
-
-
- clip_4_palette(wPtr);
-
- my_rgn = NewRgn();
- ScrollRect(&bounds_rect, h_scroll, v_scroll, my_rgn);
- InvalRgn(my_rgn);
-
-
- SetClip(saved_clip);
-
- DisposeRgn(my_rgn);
- DisposeRgn(saved_clip);
-
-
-
- /************* Update the scroll offset value in WObjs record **********/
-
-
- offset.h -= h_scroll;
- offset.v -= v_scroll;
-
- if(wPtr == gProgWindow)
- {
- (**wp_objs_hndl).scrollAmount = offset;
- }
- else
- {
- (**w_objs_hndl).scrollAmount = offset;
- }
-
-
- /********* Process the update immediately **********/
-
-
- do_update(wPtr);
-
- while (TickCount() < start_ticks + min_delay) {};
-
-
- } /* end of do_scroll() */
-